package com.zqs.compareface.server.imageProcess;

import com.zqs.compareface.server.commit.CommitApiOrLocal;
import com.zqs.compareface.utils.impl.MyLogUtil;
import org.opencv.core.Mat;

import java.util.Iterator;
import java.util.Set;


/**
 * @Program: FaceCompare
 * @Description:
 * @Author: zqs
 * @Create： 2021-08-11-22:36
 */
public class DoSwitch {
    int i;
    String keyValue = null;
    private SaveOrConvertFaceImage saveOrConvertFaceImage;
    private double result;

    public DoSwitch(double result) {
        this.result = result;
    }

    public DoSwitch(int i, SaveOrConvertFaceImage saveOrConvertFaceImage) {
        this.i = i;
        this.saveOrConvertFaceImage = saveOrConvertFaceImage;
    }

    public DoSwitch() {
    }
    public void contrast(double result,String bas64code){
       if (result > 0.50 && result < 0.7) {
            MyLogUtil.log("人脸匹配不够精准，提交云端API再次处理");
            baiduApi(bas64code);
        } else {
            MyLogUtil.log("人脸匹配未成功");
        }
    }
    public void contrast(double result){
        if (result > 0.7) {
            System.out.println("人脸匹配成功");
        } else {
            MyLogUtil.log("人脸匹配未成功");
        }
    }

    public void doSwitch(){
        double compareResult = localContrast();
        if (compareResult > 0.72) {
            System.out.println("人脸匹配成功");
        } else if (compareResult > 0.50 && compareResult < 0.7) {
            MyLogUtil.log("人脸匹配不够精准，提交云端API再次处理");
//            baiduApi();
        } else {
            MyLogUtil.log("人脸匹配未成功");
//            baiduApi();
        }
    }
    public double localContrast(){
        Set<Mat> mapKeys = saveOrConvertFaceImage.hashMap.keySet();
        Iterator<Mat> iterator = mapKeys.iterator();
        double compareResult = 0D;
        while (iterator.hasNext()){
            Mat mapKey = iterator.next();
//            compareResult = new LocalCheckUtil().compare_allimage(mapKey);
            if(compareResult > 0.5 && compareResult <0.7){
                keyValue = saveOrConvertFaceImage.hashMap.get(mapKey);
            }else {
//                SaveOrConvertFaceImage.hashMap.remove(mapKey);
            }
        }
        return compareResult;
    }
    public static void baiduApi(String bas64code){

        String userid = "wuyifang";
        new CommitApiOrLocal().preparingData(bas64code,userid);
    }
}
